//
//  SJTableViewController.m
//  StaticLoginDemo
//
//  Created by 石显军 on 2021/10/16.
//

#import "SJTableViewController.h"
#import "SJTableViewCell.h"
#import "NSBundle+StaticLoginDemo.h"

@interface SJTableViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSArray *arrDatas;

@end

@implementation SJTableViewController

#define kCellImageName @"cellimageName"
#define kCelltitle @"title"


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"列表";
    
    self.arrDatas = @[
        @{
            kCellImageName : @"OnlinePayment",
            kCelltitle : @"OnlinePayment",
        },
        @{
            kCellImageName : @"a-2-OnlinePayment",
            kCelltitle : @"OnlinePayment",
        },
        @{
            kCellImageName : @"a-3-MobileBanking",
            kCelltitle : @"MobileBanking",
        },
        @{
            kCellImageName : @"a-4-CreditCard",
            kCelltitle : @"CreditCard",
        }
    ];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    
//    [UINib nibWithNibName:@"" bundle:<#(nullable NSBundle *)#>]
    
    [self.tableView registerNib:[UINib nibWithNibName:@"SJTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SJTableViewCell"];
    
    // Do any additional setup after loading the view.
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrDatas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SJTableViewCell" forIndexPath:indexPath];

    NSDictionary *dict = self.arrDatas[indexPath.row];
    
    NSLog(@"path : %@", [NSBundle staticLoginDemoResourceBundle].resourcePath);
    NSLog(@"path : %@", [[NSBundle staticLoginDemoResourceBundle] pathForResource:[dict objectForKey:kCellImageName] ofType:@"png"]);
    
    cell.iconView.image = [UIImage imageWithContentsOfFile:[[NSBundle staticLoginDemoResourceBundle] pathForResource:[dict objectForKey:kCellImageName] ofType:@"png"]];
//    cell.iconView.image = [UIImage imageNamed:[dict objectForKey:kCellImageName]];
    cell.lblTitle.text = [dict objectForKey:kCelltitle];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

@end
